package dm.sql.comp;


/*
 *@ 2022-10-18
 * SQL的复杂度设置
 */
public enum SQLComplexity {
    Cpx0,
    Cpx1,
    Cpx2,
    Cpx3,
    Cpx4,
    Cpx5,
    Cpx6;

    public enum ComplexLevel {
        EASY,
        MEDIUM,
        HARD,
        EXTRAHARD;
    }

    //根据AST的深度(dep_t)与宽度(wid_t)计算SQL复杂度
//Cpx0: dep_t=1, wid_t<50
//Cpx1: dep_t=1, wid_t>=50
// dep_t=2, wid_t<100
//Cpx2: dep_t=2, wid_t>=100
// dep_t=3, wid_t<200
//Cpx3: dep_t=3, wid_t>=200
// dep_t=4, wid_t<500
//Cpx4: dep_t=4, wid_t>=500
// dep_t=5, wid_t<1000
//Cpx5: dep_t=5, wid_t>=1000
// dep_t>=6, wid_t<2000
//Cpx6: dep_t>=6, wid_t>=2000
    public static int WID_LEVEL0 = 50;
    public static int WID_LEVEL1 = 100;
    public static int WID_LEVEL2 = 200;
    public static int WID_LEVEL3 = 500;
    public static int WID_LEVEL4 = 1000;
    public static int WID_LEVEL5 = 2000;

    public static SQLComplexity sqlComplex(int dep_t, int wid_t) {
        switch (dep_t) {
            case 0:
            case 1: //dep_t = 1
                if (wid_t < WID_LEVEL0) {
                    return Cpx0;
                } else {
                    return Cpx1;
                }
            case 2: //dep_t = 2
                if (wid_t < WID_LEVEL1) {
                    return Cpx1;
                } else {
                    return Cpx2;
                }
            case 3: //dep_t = 3
                if (wid_t < WID_LEVEL2) {
                    return Cpx2;
                } else {
                    return Cpx3;
                }
            case 4: //dep_t = 4
                if (wid_t < WID_LEVEL3) {
                    return Cpx3;
                } else {
                    return Cpx4;
                }
            case 5: //dep_t = 5
                if (wid_t < WID_LEVEL4) {
                    return Cpx4;
                } else {
                    return Cpx5;
                }
            default: //dep_t >= 6
                if (wid_t < WID_LEVEL5) {
                    return Cpx5;
                } else {
                    return Cpx6;
                }
        }
    }

    //根据SQL复杂度返回SQL复杂度度量级
    public static ComplexLevel sqlComplexLevel(SQLComplexity sqlcomplex) {
        switch (sqlcomplex) {
            case Cpx0:
                return ComplexLevel.EASY;
            case Cpx1:
            case Cpx2:
                return ComplexLevel.MEDIUM;
            case Cpx3:
            case Cpx4:
                return ComplexLevel.HARD;
            case Cpx5:
            case Cpx6:
                return ComplexLevel.EXTRAHARD;
            default:
                throw new AssertionError();
        }
    }

    //根据AST的宽度(wid_t)与深度(dep_t)计算SQL复杂度度量级
    public static ComplexLevel sqlComplexLevel(int dep_t, int wid_t) {
        return sqlComplexLevel(sqlComplex(dep_t, wid_t));
    }
}

